package ca.camosun.proximity;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	Room theRoom = Room.getInstance();
	int currentList=1;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	public void engage(View v) {
		
		setContentView(R.layout.local_devices);

		//Intent scanUsingBluetooth = new Intent(MainActivity.this, BluetoothScan.class);
		//MainActivity.this.startActivity(scanUsingBluetooth);
		
		displayNearby(v);
		
	}
	
	public void showMenu(View v) {
		PopupMenu popup = new PopupMenu(this, v);
	    MenuInflater inflater = popup.getMenuInflater();
	    inflater.inflate(R.menu.activity_main, popup.getMenu());
	    popup.show();
	}
	
	public void displayNearby(View v) {
		
		String[] myStringArray = theRoom.listOfDevicesInRoom();
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
		        android.R.layout.simple_list_item_1, myStringArray);
		        
		ListView listView = (ListView) findViewById(R.id.devicesInRoomList);
		listView.setAdapter(adapter);
		
		final TextView MenuHead = (TextView) findViewById(R.id.menuHead);
		MenuHead.setText(
		    "Nearby Devices");
	}
	
	public void displayKnown(View v) {
		
		String[] myStringArray = theRoom.listOfKnownDevices();
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
		        android.R.layout.simple_list_item_1, myStringArray);
		        
		ListView listView = (ListView) findViewById(R.id.devicesInRoomList);
		listView.setAdapter(adapter);
		
		final TextView MenuHead = (TextView) findViewById(R.id.menuHead);
		MenuHead.setText(
		    "Known Devices");
		
	}
	
	public void displayUnknown(View v) {
		
		String[] myStringArray = theRoom.listOfUnknownDevices();
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
		        android.R.layout.simple_list_item_1, myStringArray);
		        
		ListView listView = (ListView) findViewById(R.id.devicesInRoomList);
		listView.setAdapter(adapter);
		
		final TextView MenuHead = (TextView) findViewById(R.id.menuHead);
		MenuHead.setText(
		    "Unknown Devices");
		
	}

}
